from Sodev.file import  File 
from Sodev.blockHDD import BlockHDD
from Sodev.folder import Folder

class FileSystem:
    def __init__(self):
        self.folder = None
        
    def search (self,path):
        return self.folder.search(path)
    
    def obtainIndexOf(self,harddrive):
        self.folder = harddrive.getIndex()
        
    #Data debe ser un folder, o un file.    
    def write (self,path,data):
        if(data.isFolder()):
            self.folder.writeFolder(path,data,self)
        else:
            self.folder.writeFile(path,data)
    
    def createFolder(self,name,path):
        folder = Folder(name)
        self.write(path, folder)
            
    def writeProgram(self,path,programa):
        file = File(programa.getNombre())
        file.setData(self.install(programa.getInstr()))
        self.write(path, file)
    
    def install(self,insts):
        bloquesHDD = []
        bloquehdd = BlockHDD()
        for inst in insts:
            if(bloquehdd.size() < 10):
                bloquehdd.setInstr(inst)
            else:
                bloquesHDD.append(bloquehdd)
                bloquehdd = BlockHDD()
        bloquesHDD.append(bloquehdd)
        return bloquesHDD
    
        
        
    
        